<template>
    <view id="certitfy">
        <view>
            <view @tap="chooseAddress" class="address_1">
                <view>
                    <view class="choose_bank_box" >
                        <view class="choose_text">姓名：{{name}}</view>
                        <view class="bank_name">收货电话：{{mobile}}</view>
                        <!--                    <view class="bank_info_box">-->
                        <!--                        <view class="bank_logo_box">-->
                        <!--                            <view class="bank_name">收货电话：</view>-->
                        <!--                        </view>-->
                        <!--                    </view>-->
                        <view class="arrow_box"><image  class="arrow_img"  :src="imgUrl+'/static/img/jiantou.png'"/></view>

                    </view>
                    <view class="address_detail">详细地址：{{address_info}}</view>
                </view>

            </view>
            <view>
                <van-field
                        type="number"
                        :value="number"
                        placeholder="请输入提货数量"
                        label="提货数量："
                        input-align="left"
                        :border="has_boder"
                        @input="confirm2"
                        maxlength="4"

                />
            </view>
            <view>
                <van-field
                        :value="remark"
                        placeholder="请输入备注(选填)"
                        :label="label"
                        input-align="left"
                        :border="has_boder"
                        @input="confirm1"
                />
            </view>

        </view>


        <view class="yun_tips">运费：寄付</view>
        <view class="button-submit" @tap="commit()">
            <van-button type="info" round size="large" color="#FF9503" >确定</van-button>
        </view>
    </view>
</template>

<script>
    import MInput from '@/components/m-input.vue'
    export default{
        name:"groupWalletPick",
        data(){
            return {
                profit_position_id:'',
                has_boder: true,
                number:'0',
                remark:'',
                address_info:'',
                address_id:'',
                label:'',
                is_business: 0,
                choose_address_id:'',
                imgUrl:this.$mConfig.assetsPath,
                name:'',
                mobile:'',
            }

        },
        onLoad(query){
            // let market_value=query.market_value
            // if(market_value>=1){
            //     this.number=1
            // }else{
            //     this.number=0
            // }
            // if(query.is_business!==undefined && query.is_business>0){
            //     this.is_business=1
            // }
            // this.profit_position_id=query.profit_position_id
        },
        onShow(){
            this.choose_address_id=this.$store.state.chooseAddressId
            this.getAddressInfo()
        },
        mounted(){
        },
        methods:{
            pingConfirm(item){//拼团确认
                if(!this.ping_checked){
                    uni.showToast({
                        title:"请先阅读并同意电子协议",
                        icon:"none",
                        duration: 3000,
                    })
                    return
                }else{
                    this.ping_show=false
                }

            },
            buyClose(){//立即购买弹窗关闭
                this.show=false
                this.ping_show=false
            },
            chooseAddress(){
                this.$router.push({
                    route:this.$routesConfig.addressList,
                })
            },


            async commit(){ //确认提交
                if(this.address_id==='' || this.address_info===''){
                    uni.showToast({
                        title:"请设置收货地址",
                        icon:"none",
                    })
                    return
                }
               let regNumber = /^\+?[1-9][0-9]*$/;
                if(regNumber.test(this.number) === false) {
                    uni.showToast({
                        title:"请输入大于等于0的提货数量",
                        icon:"none",
                        duration:3000
                    })
                    return
                }

                let user_data = await this.$apis.getUserInfo({access_token:''})
                if(user_data.data.group_wallet_money<(parseInt(1500*this.number))){
                    uni.showToast({
                        title:"您的购货券余额不足，请重新输入数量！",
                        icon:"none",
                        duration:3000
                    })
                    return
                }

                uni.showLoading({})
                if(this.number>0){  // 购货券提货
                    let res =await  this.$apis.groupPickUp({address_id:this.address_id,position_id:this.profit_position_id,remark:this.remark,number:this.number})
                    if(res.code===0){
                        uni.showToast({
                            title:"提货成功",
                            icon:"success",
                        })
                        setTimeout(()=>{
                            uni.navigateBack({
                                delta: 1 // 代表返回上 1 页
                            })
                        },1000)
                    }
                }
                uni.hideLoading()
            },

            confirm1(event){
                this.remark=event.detail
            },
            confirm2(event){
                this.number=event.detail
            },
            async getAddressInfo(){ // 获取默认地址,如果没有默认地址则去取第一个地址
                if(this.choose_address_id!==''){
                    let resData = await this.$apis.getAddressInfo({id:this.choose_address_id})
                    this.address_info=resData.data.address.province+resData.data.address.city+resData.data.address.district+resData.data.address.house_number
                    this.address_id=resData.data.address.id
                    this.mobile=resData.data.address.mobile
                    this.name=resData.data.address.realname
                }else{
                    let resData = await this.$apis.getDefaultAddress({access_token:''})
                    if(resData.data.address.id!==undefined){
                        this.address_info=resData.data.address.province+resData.data.address.city+resData.data.address.district+resData.data.address.house_number
                        this.address_id=resData.data.address.id
                        this.mobile=resData.data.address.mobile
                        this.name=resData.data.address.realname
                    }else{
                        let otherAddress = await  this.$apis.getAddressList({access_token:''})
                        if(otherAddress.data.addressList.length>0){
                            this.address_info=otherAddress.data.addressList[0].province+otherAddress.data.addressList[0].city+otherAddress.data.addressList[0].district+otherAddress.data.addressList[0].house_number
                            this.address_id=otherAddress.data.addressList[0].id
                            this.mobile=resData.data.addressList[0].mobile
                            this.name=resData.data.addressList[0].realname
                        }
                    }
                }

            },
            sure(res){ // 子组件传递过来的东西
                this.tips_show=res;
            }
        },
        components:{
            MInput
        }
    }
</script>

<style lang="less" scoped>
    .button-submit{
        width: 90%;
        margin-left: 5%;
        margin-top: 10rpx;
    }
    .tips{
        position: fixed;
        width: 100%;
        bottom: 20rpx;
        font-size: 25rpx;
        text-align: center;
        color: red;
    }
    .yun_tips{
        color: #F22732;
        font-size: 26rpx;
        margin-left: 35rpx;
        margin-top: 20rpx;
        margin-bottom: 30rpx;
    }
    .choose_bank_box{
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        padding-top: 20rpx;
        padding-bottom: 20rpx;
        padding-left: 20rpx;
        padding-right: 20rpx;

    }
    .choose_text{
        font-size: 28rpx;
        color: #333333;
        padding-left: 10rpx;
        /*padding-top: 20rpx;*/
    }
    .bank_logo_box{
        display: flex;
        flex-direction: row;
        justify-content: left;
    }
    .bank_logo{
        width: 30rpx;
        height: 30rpx;
    }
    .bank_name{
        font-size: 28rpx;
        color: #333333;
        padding-left: 10rpx;
    }
    .bank_num{
        font-size: 28rpx;
        color: #333333;
        padding-top: 10rpx;
    }
    .arrow_box{
        padding-top: 20rpx;
    }
    .arrow_img{
        width: 30rpx;
        height: 30rpx;
    }
    .address_1{
        background-color: #FAFAFA;
        padding-bottom: 20rpx
    }
    .address_detail{
        font-size: 28rpx;
        color: #333333;
        padding-left: 30rpx;
        padding-right: 20rpx;
    }
</style>
